﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.Xml.Serialization;
using TopShooter.Items;

namespace TopShooter
{
	[XmlInclude(typeof(Info))]
	[XmlInclude(typeof(ExplosiveBarrelInfo))]
	[XmlInclude(typeof(InfantryInfo))]
	[Serializable]
	public abstract class Info
	{
		[XmlIgnore]
		public Vector2 Location { get { return new Vector2(X, Y); } set { X = value.X; Y = value.Y; } }

		[XmlAttribute]
		public float X;
		[XmlAttribute]
		public float Y;
		[XmlAttribute]
		public float Health;

		protected Info() { }

		public Info(Entity entity)
		{
			this.Location = entity.Location;
			this.Health = entity.Health;
		}

		abstract public void Create(Scene scene);

		protected void Initialize(Entity entity)
		{
			entity.Health = Health;
			entity.Location = Location;
		}
	}

	public class InfantryInfo : Info
	{
		public int TeamID;

		public string WeaponName = "Spear";

		private InfantryInfo() { }

		public InfantryInfo(Units.Infantry inf)
			: base(inf)
		{
			TeamID = inf.TeamID;
			WeaponName = inf.Weapon.Name;
			
		}

		public override void Create(Scene scene)
		{
			Weapon w = Assets.Weapons.Registry[WeaponName].Clone() as Weapon;
			Units.Infantry inf = new Units.Infantry(TeamID, w);
			inf.AddToScene(scene, Location);
			Initialize(inf);
		}
	}

	public class ExplosiveBarrelInfo : Info
	{
		private ExplosiveBarrelInfo() { }

		public ExplosiveBarrelInfo(ExplosiveBarrel ep)
			: base(ep)
		{
		}

		public override void Create(Scene scene)
		{
			ExplosiveBarrel ep = new ExplosiveBarrel();
			ep.AddToScene(scene, Location);
			Initialize(ep);
		}

	}
}
